#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int x,n,odd=0,eve=0,res=0,ans=0,l1=1,l2=2;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&x);
			if(x&1)
			{
				odd++;
				res+=abs(l1-i);
				ans+=abs(l2-i);
				l1+=2,l2+=2;	
			}
			else eve++;
		}
		if(odd == eve) printf("%d\n",min(res,ans));
		else if(odd + 1 == eve) printf("%d\n",ans);
		else if(odd == eve + 1) printf("%d\n",res);
		else puts("-1");
	}
	return 0;
}
